/**
 *
 */
package cn.hg.jfsa.manage.controller.module.goods.validator;

import com.jfinal.core.Controller;

import cn.hg.base.jfinal.validator.BaseValidator;
import cn.hg.jfsa.model.Goods;

/**
 * @author Golly
 */
public class GoodsValidator extends BaseValidator {

	/*
	 * (non-Javadoc)
	 * @see com.jfinal.validate.Validator#handleError(com.jfinal.core.Controller)
	 */
	@Override
	protected void handleError (Controller c) {
		Goods bean = c.getBean(Goods.class);

		if (bean.getId() == null) {
			c.setAttr("goods", bean);
			c.keepPara();
			c.render("/admin/goods/goods/add.html");
		} else {
			c.redirect("/admin/goods/edit?id=" + bean.getId());
		}

	}

	/*
	 * (non-Javadoc)
	 * @see com.jfinal.validate.Validator#validate(com.jfinal.core.Controller)
	 */
	@Override
	protected void validate (Controller c) {
		this.setShortCircuit(true);
		this.validateRequired("goods.categoryId", "categoryMsg", "分类为必填！");
		this.validateRequired("goods.typeId", "typeMsg", "类型为必填！");
		this.validateRequired("goods.status", "statusMsg", "状态为必填！");
		this.validateString("goods.title", 3, 100, "titleMsg", "标题必须填写3到100长度的字符！");
	}

}
